package com.snail.mobile.sim.oss.util;

import javax.servlet.http.HttpServletRequest;

public class Tools {

	private Tools(){}

	//获取当前用户IP  
    public static String getRemoteHost(HttpServletRequest request) {  
    	
    	String host = request.getHeader("x-forwarded-for");  
    	 if (host == null || host.length() == 0 || "unknown".equalsIgnoreCase(host)) {  
    		 host = request.getHeader("Proxy-Client-IP");  
    	 }  
    	 if (host == null || host.length() == 0 || "unknown".equalsIgnoreCase(host)) {  
    		 host = request.getHeader("WL-Proxy-Client-IP");  
    	 }  
    	 if (host == null || host.length() == 0 || "unknown".equalsIgnoreCase(host)) {  
    		 host = request.getRemoteAddr();  
    	 }  
    	 if (host == null || host.length() == 0 || "unknown".equalsIgnoreCase(host)) {  
    		 host = request.getHeader("http_client_ip");  
    	 }  
    	 if (host == null || host.length() == 0 || "unknown".equalsIgnoreCase(host)) {  
    		 host = request.getHeader("HTTP_X_FORWARDED_FOR");  
    	 }  
    	 // 如果是多级代理，那么取第一个ip为客户ip  
    	 if (host != null && host.indexOf(",") != -1) {  
    		 host = host.substring(host.lastIndexOf(",") + 1, host.length()).trim();  
    	 }  
    	 return host;  
    }  

}
